package com.fot.core.publisher;

import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBlockingQueue;
import org.redisson.api.RedissonClient;

/**
 * @author 殷豪
 */
@Slf4j
public class RedisMQMessagePublisher implements MessagePublisher {
    private final RedissonClient redissonClient;

    public RedisMQMessagePublisher(RedissonClient redissonClient) {
        this.redissonClient = redissonClient;
    }
    @Override
    public boolean publish(String topic, String message) {
        RBlockingQueue<Object> queue = redissonClient.getBlockingQueue(topic);
        boolean success = queue.offer(message);
        if (!success) {
            log.warn("redis message publish failed. topic:{}, message:{}", topic, message);
            return false;
        }

        return true;
    }
}
